﻿
using System.Security.Cryptography;
using System.Text;

namespace wt.wine.Application.Common.Utils
{
    public class MD5Encrypt
    {
        public static string GetMd5Hash(string value)
        {
            if (!string.IsNullOrWhiteSpace(value))
            {
                // 将输入字符串转换为字节数组
                byte[] byteArray = Encoding.UTF8.GetBytes(value);
                // 使用MD5算法对字节数组进行哈希
                byte[] hashBytes;
                using (MD5 md5Hash = MD5.Create())
                {
                    hashBytes = md5Hash.ComputeHash(byteArray);
                }
                // 将哈希字节数组转换为十六进制字符串
                StringBuilder hexString = new StringBuilder(hashBytes.Length * 2);
                foreach (byte b in hashBytes)
                {
                    hexString.AppendFormat("{0:x2}", b);
                }
                return hexString.ToString().ToLower().Substring(8,16);
            }
            else {
                return "";
            }
        }
    }
}
